#include"processBar.h"
#include<string.h>

#define GREEN "\033[0;32;42m"
#define NONE "\033[m"

const char* Revole = "|/-\\";
//v1.0
void processBar(int speed)
{
    char bar[NUM] = {0};
    memset(bar,'\0',sizeof(bar));
    int cnt = 0;
    int len = strlen(Revole);
    while(cnt <= 100)
    {
        printf(GREEN"[%-100s]"NONE"[%%%d][%c]\r",bar,cnt,Revole[cnt%len]);
        fflush(stdout);
        usleep(100000);
        bar[cnt++] = '#';
        if ( cnt < 100 ) bar[cnt] = '>';
    }
}

char bar[NUM];
char space[101];
void processBarCore(int rate)
{
    int len = strlen(Revole);
    space[100] = '\0';
    //先判断rate的有效性
    if(rate < 0 || rate > 100)
    {
        printf("进度无效");
        return;
    }
    memset(space, ' ', 100-rate);
    printf(GREEN"[%s"NONE"%s]""[%%%d][%c]\r",bar, space, rate,Revole[rate%len]);
    fflush(stdout);
    memset(space,'\0',sizeof(space));
    bar[rate++] = BODY;
    if(rate < 100) bar[rate] = RIGHT;
    else if(rate > 100) memset(bar,'\0', sizeof(bar));
}
